const {User} = require('../../model/user');

module.exports = async (req, res) => {
    //获取地址栏的id参数
    const {message, id} = req.query;
    //传递了id说明是修改
    if (id) {
        //修改操作
        let user = await User.findOne({_id: id});
        //渲染用户编辑
        res.render('admin/user-edit', {message, user, link: `/admin/user-modify?id=${id}`, button: '修改'});
    } else {//添加
        res.render('admin/user-edit', {message, link: '/admin/user-edit', button: '添加'});
    }
};
